package edu.fim.core.service.locator;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanLocator {

	private static final BeanLocator INSTANCE = new BeanLocator();
	
	private ApplicationContext context;
	
	private BeanLocator() {
		context = new ClassPathXmlApplicationContext("META-INF/applicationContext.xml");
	}

	public static BeanLocator getInstance() {
		return INSTANCE;
	}
	
	public static void initialize() {
	}
	
	public <T> T getBean(Class<T> clazz) {
		return context.getBean(clazz);
	}
	
	@SuppressWarnings("unchecked")
	public <T> T getServiceBean(Class<T> interFace) {
		T type = ServiceLocator.getImplementation(interFace);
		return (T) context.getBean(type.getClass().getSimpleName());
	}
}